<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script type="text/javascript" src="js/global.js"></script>
		<script src="./layui/layui.js"></script>
	</head>

	<body>
		<form class="layui-form" onsubmit="false">
			<div hidden="hidden" class="layui-form-item" style="margin-top: 20px">
				<label class="layui-form-label">ID：</label>
				<div class="layui-input-inline" style="width: 350px">
					<input type="text" name="id" id="id" required lay-verify="required" placeholder=""
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="margin-top: 20px">
				<label class="layui-form-label">部门名：</label>
				<div class="layui-input-inline" style="width: 350px">
					<input type="text" name="sname" id="sname" required lay-verify="required" placeholder=""
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<!-- 文本域 -->
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">部门描述</label>
				<div class="layui-input-block" style="width: 350px;">
					<textarea placeholder="请输入内容" class="layui-textarea" name="sintroduce" id="sintroduce"></textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-btn-container" style="text-align: center;">
					<button class="layui-btn" lay-submit lay-filter="formDemo">编辑</button>
				</div>
			</div>
		</form>

		<script>
			//Demo
			layui.use(['form', 'jquery', 'layer'], function() {
				var form = layui.form;
				var $ = layui.jquery;
				//解决跨域
				$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
					options.xhrFields = {
						withCredentials: true
					}
				})
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var d = data.field; //表单中的数据，定义一个对象来接收
					var url = globalData.server + './section/updateSection';
					$.post(url, d, function(data) {
						console.log("我是d：" + d);
						console.log(data)
						console.log(data.sintroduce)

						if (data > 0) {
							layer.msg(data.msg, {
								icon: 6
							});
							var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //再执行关闭   
						} else {
							layer.msg(data.msg, {
								icon: 6
							});
						}
					}, "json");
					return false;
				});
			});
		</script>
	</body>

</html>
